package com.hk.service.business;

import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@Slf4j
public class SchedulerBusiness {


    /**
     * 定时任务1秒种执行一次，但是只会在执行一分钟后才会再执行，锁住
     * PT5M-意味着此方法将至少保持锁定五分钟
     * PT1M-意味着此方法将至少保持锁定一分钟
     *
     * 2023-02-27 18:24:00.046 [] [scheduling-1] [INFO ] c.h.s.business.SchedulerBusiness:18 TaskScheduler_test - 当前服务的时间为：2023-02-27T18:24:00.046
     * 2023-02-27 18:25:00.021 [] [scheduling-1] [INFO ] c.h.s.business.SchedulerBusiness:18 TaskScheduler_test - 当前服务的时间为：2023-02-27T18:25:00.021
     * 2023-02-27 18:26:00.027 [] [scheduling-1] [INFO ] c.h.s.business.SchedulerBusiness:18 TaskScheduler_test - 当前服务的时间为：2023-02-27T18:26:00.027
     * 2023-02-27 18:27:00.017 [] [scheduling-1] [INFO ] c.h.s.business.SchedulerBusiness:18 TaskScheduler_test - 当前服务的时间为：2023-02-27T18:27:00.017
     * 2023-02-27 18:28:00.023 [] [scheduling-1] [INFO ] c.h.s.business.SchedulerBusiness:18 TaskScheduler_test - 当前服务的时间为：2023-02-27T18:28:00.023
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    @SchedulerLock(name = "TaskScheduler_test", lockAtLeastForString = "PT1M", lockAtMostForString = "PT1M")
    public void TaskScheduler_test() {
      log.info("当前服务的时间为：{}", LocalDateTime.now());
    }

}
